package com.you.modules.activemq.bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

@Component("activeMqQueueProducer")
public class ActiveMqQueueProducer implements IActiveMqProducer {
    @Autowired
    @Qualifier("jmsQueueTemplate")
    private JmsTemplate jmsQueueTemplate;

    /**
     *activemq消息发送方法
     *
     * @author : liuyang53 2018-07-16 星期一 下午 04:38:17
     * @param destination : 目标队列
     * @param message : 消息内容
     * @return : void
     */
    @Override
    public void send(String destination, Object message) {
        jmsQueueTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return jmsQueueTemplate.getMessageConverter().toMessage(message,session);
            }
        });
    }
}
